package com.tao.mywheelview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.ViewGroup;

import com.tao.contrarywind.adapter.ArrayWheelAdapter;
import com.tao.contrarywind.adapter.NumericWheelAdapter;
import com.tao.contrarywind.listener.OnItemSelectedListener;
import com.tao.contrarywind.view.WheelView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initWheel();
    }
    private WheelView wl01;
    private WheelView wl02;
    private void initWheel() {

        wl01 = new WheelView(this);
        wl02 = findViewById(R.id.wl02);
        wl02.setFixNum(false);
        wl01.setFixNum(false);
//        wl02.setForceTouchEvent(false);

//        wl01.setAdapter(new ArrayWheelAdapter(getNumberList()));
//        wl02.setAdapter(new ArrayWheelAdapter(getNumberList()));
        wl01.setAdapter(new NumericWheelAdapter(0,9));
        wl02.setAdapter(new NumericWheelAdapter(0,9));
        wl01.setItemsVisibleCount(5);
        wl02.setItemsVisibleCount(5);
        wl01.setCyclic(true);
        wl01.setLineSpacingMultiplier(1.1f);
        wl02.setLineSpacingMultiplier(1.1f);
        wl01.setCurrentItem(0);
        wl02.setCurrentItem(0);
        wl02.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                
                Object item = wl02.getAdapter().getItem(index);
            }
        });   wl01.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                
                Object item = wl02.getAdapter().getItem(index);
            }
        });
        ((ViewGroup)findViewById(R.id.ll_o1)).addView(wl01);
    }
    private List<Integer> getNumberList() {
        List<Integer> nums =new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            nums.add(i);
        }
        return nums;
    }

}